package terminal.database;

import java.util.ArrayList;

import terminal.database.model.Node;
import terminal.database.repositories.NodeRepository;
import core.database.NodeType;


public class DatabaseManager extends core.managers.DatabaseManager<Node, NodeRepository> {

	public Node getMainNode() {
		ArrayList<Node> nodesList = nodeRepository.findByLevel(0);
		if (!nodesList.isEmpty())
			return nodesList.get(0);
		else
			return null;
	}

	public Node getRKW() {
		return nodeRepository.findByNodeType(NodeType.RKW);
	}

	@Override
	protected Node getNewEmptyNode() {
		return new Node();
	}

	@Override
	public void savePrefferedParentURI(String prefferedParentURI) {
	}

	@Override
	public Node convertToDatabaseNode(core.database.Node node) {
		Node dbNode = new Node();
		dbNode.setAddress(node.getAddress());
		dbNode.setIp(node.getIp());
		dbNode.setLevel(node.getLevel());
		dbNode.setName(node.getName());
		dbNode.setNodeType(node.getNodeType());
		dbNode.setPort(node.getPort());
		return dbNode;
	}
}
